package com.winway.sixbook.custom;
  
import com.winway.sixbook.R;

import android.content.Context;  
import android.database.Cursor;  
import android.graphics.Color;  
import android.view.LayoutInflater;
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;  
import android.widget.TextView;
  
public class MySimpleCursorAdapter extends SimpleCursorAdapter {  
  
	//声明LayoutInflater用于查找XML布局
	private LayoutInflater mInflater; 
    public MySimpleCursorAdapter(Context context, int layout, Cursor c,  
            String[] from, int[] to) {  
        super(context, layout, c, from, to);  
        // TODO Auto-generated constructor stub  
  
    }  
  
    @Override  
    public View getView(final int position, View convertView, ViewGroup parent) {  
        // TODO Auto-generated method stub  
        // listview每次得到一个item，都要view去绘制，通过getView方法得到view  
        // position为item的序号  
        View view = null;  
        if (convertView != null) {  
            view = convertView;  
            // 使用缓存的view,节约内存  
            // 当listview的item过多时，拖动会遮住一部分item，被遮住的item的view就是convertView保存着。  
            // 当滚动条回到之前被遮住的item时，直接使用convertView，而不必再去new view()  
  
        } else {  
            view = super.getView(position, convertView, parent);  
  
        }  
  
        int[] colors = { Color.WHITE, Color.rgb(219, 238, 244) };//RGB颜色  
  
        view.setBackgroundColor(colors[position % 2]);// 每隔item之间颜色不同  
  
        return super.getView(position, view, parent);  
    }
    
    /*
	  * 重写此方法
	  */
	 @Override
	 public void bindView(View view, Context context, Cursor cursor) {
		  LinearLayout layout = null;
		  if(view==null)
		  {
			  layout = (LinearLayout) mInflater.inflate(R.layout.listviewlayout,null);
		  }
		  else
		  {
			  layout = (LinearLayout)view;
		  }
		  
		  TextView recordid = (TextView)layout.findViewById(R.id.recordid);
		  TextView zzjl = (TextView)layout.findViewById(R.id.zzjl);
		  TextView sj_hour = (TextView)layout.findViewById(R.id.sj_hour);
		  TextView sj_min = (TextView)layout.findViewById(R.id.sj_min);
		  TextView sj_sec = (TextView)layout.findViewById(R.id.sj_sec);
		  TextView zmstr = (TextView)layout.findViewById(R.id.zmstr);
		  TextView fmstr = (TextView)layout.findViewById(R.id.fmstr);
		  TextView wystr = (TextView)layout.findViewById(R.id.wystr);
		  ImageView image1 = (ImageView)layout.findViewById(R.id.image1);
		  ImageView image2 = (ImageView)layout.findViewById(R.id.image2);
		  
		  String isdo = cursor.getString(cursor.getColumnIndex("isdo"));
		  
		  recordid.setText(cursor.getString(cursor.getColumnIndex("_id")));
		  zzjl.setText(cursor.getString(cursor.getColumnIndex("type_name")));
		  sj_hour.setText(cursor.getString(cursor.getColumnIndex("add_hour")));
		  sj_min.setText(cursor.getString(cursor.getColumnIndex("add_min")));
		  sj_sec.setText(cursor.getString(cursor.getColumnIndex("add_sec")));
		  zmstr.setText(cursor.getString(cursor.getColumnIndex("content_zm")));
		  fmstr.setText(cursor.getString(cursor.getColumnIndex("content_fm")));
		  wystr.setText(cursor.getString(cursor.getColumnIndex("content_wy")));
		  
		  if(null == isdo || "".equals(isdo)){
			  isdo = "0";
		  }
		  if(Integer.parseInt(isdo)==0){
			  image1.setVisibility(View.VISIBLE);
			  image2.setVisibility(View.GONE);
		  }else{
			  image1.setVisibility(View.GONE);
			  image2.setVisibility(View.VISIBLE);
		  }
		  
	 }
  
}  
